#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

typedef struct oper
{
    char op;
    char* arr;
}ope;
#define BUF_SIZE 1024
int main(){

    //创建套接字
    int sock = socket(PF_INET, SOCK_STREAM, 0);
    //向服务器（特定的IP和端口）发起请求
    struct sockaddr_in serv_addr;
    memset(&serv_addr, 0, sizeof(serv_addr));  //每个字节都用0填充
    serv_addr.sin_family = AF_INET;  //使用IPv4地址
    serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");  //具体的IP地址
    //作用同：inet_aton("127.0.0.1",&serv_addr.sin_addr);
    serv_addr.sin_port = htons(1234);  //端口
    connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    ope o;
    char arr[10]; 
    o.arr = arr;
    o.op = '\0';
    //读取服务器传回的数据
    char buffer[BUF_SIZE];
    int str_len=0,idx=0,read_len = 0;
    
    fputs("insert numbers of opsize:\n",stdout);
    gets(o.arr);

    fputs("insert op:\n",stdout);
    gets(&(o.op));

    for(int i = 0;i<((o.arr)[0]-'0');i++)
    {
        fputs("insert num:\n",stdout);
        gets(o.arr+i+1);
    }

    write(sock,&o,sizeof(o));
    double res = 0;
    read(sock,&res,sizeof(res));
    printf("result form server: %s",res);

    close(sock);
    return 0;
}
